const { Controller } = require("egg");
class UserController extends Controller {
  // 小程序用户登录
  async wxLogin() {
    const { ctx, service } = this;
    const { code } = ctx.query;
    console.log(code);
    ctx.validate({ code: { type: "nullValue", fieldName: "code" } }, ctx.query);
    const res = await service.userinfo.wxLogin(code);
    ctx.send(res);
  }
  // 修改用户信息
  async updateUserInfo() {
    const { ctx } = this;
    const { nickname, avatar, phone, gender, birthday } = ctx.request.body;
    ctx.validate({
      nickname: { type: "nullValue", fieldName: "昵称" },
      avatar: { type: "nullValue", fieldName: "头像" },
    });
    const res = await ctx.model.Userinfo.findOneAndUpdate(
      { _id: ctx.auth._id },
      { nickname, avatar, phone, gender, birthday }
    );
    ctx.send({ msg: "成功", data: res });
  }
}
module.exports = UserController;
